/**
 * Copyright (c) 2012, Camelot and/or its affiliates. All rights reserved.
 * Camelot PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.camelot.ccr.system.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.camelot.ccr.global.controller.BaseController;
import com.camelot.ccr.system.dao.DriverDao;
import com.camelot.ccr.system.dao.PictureDao;
import com.camelot.ccr.system.dao.SponsorTeamDao;
import com.camelot.ccr.system.dao.TeamDao;
import com.camelot.ccr.system.dao.VideoDao;
import com.camelot.ccr.system.enums.ModuleEnum;
import com.camelot.ccr.system.persistence.Driver;
import com.camelot.ccr.system.persistence.MatchTeam;
import com.camelot.ccr.system.persistence.Picture;
import com.camelot.ccr.system.persistence.Sponsor;
import com.camelot.ccr.system.persistence.Team;
import com.camelot.ccr.system.persistence.Video;

/**
 * <pre>
 * 车队信息Controller
 * </pre>
 * @author Liu Jun
 * @version V0.1, 2014-5-23 下午2:11:38
 */
@Controller
@RequestMapping("/index")
public class IndexController extends BaseController {

	@Resource
	private PictureDao pictureDao;
	@Resource
	private VideoDao videoDao;
	@Resource
	private TeamDao teamDao;
	@Resource
	private DriverDao driverDao;
	@Resource
	private SponsorTeamDao sponsorTeamDao;
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/yueye")
	public String yueye(MatchTeam matchTeam,ModelMap model){
		List<Picture> pictureList = pictureDao.getAll();
		model.put("pictureList", pictureList);
		return "/front/yueye";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/lali")
	public String lali(MatchTeam matchTeam,ModelMap model){
		List<Picture> pictureList = pictureDao.getAll();
		model.put("pictureList", pictureList);
		return "/front/lali";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/other")
	public String other(MatchTeam matchTeam,ModelMap model){
//		List<MatchTeam> list = matchTeamDao.findByExample(matchTeam);
//		List<MatchType> matchTypeList = matchTypeDao.getAll();
		
//		model.put("list", list);
//		model.put("matchTypeList", matchTypeList);
		return "/front/other";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/teamDriver")
	public String teamDriver(ModelMap model){
		
		List<Team> teamList = teamDao.randGetList();
		List<Driver> driverList = driverDao.randGetList();
		
		model.put("teamList", teamList);
		model.put("driverList", driverList);
		return "/front/teamDriver";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/about")
	public String about(MatchTeam matchTeam,ModelMap model){
//		List<MatchTeam> list = matchTeamDao.findByExample(matchTeam);
//		List<MatchType> matchTypeList = matchTypeDao.getAll();
		
//		model.put("list", list);
//		model.put("matchTypeList", matchTypeList);
		return "/front/about";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/videoNews")
	public String videoNews(MatchTeam matchTeam,ModelMap model){
		List<Video> videoList = videoDao.getAll();
		model.put("videoList", videoList);
		return "/front/videoNews";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/picNews")
	public String picNews(MatchTeam matchTeam,ModelMap model){
		List<Picture> pictureList = pictureDao.getAll();
		model.put("pictureList", pictureList);
		return "/front/picNews";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param matchTeam
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/driver")
	public String driver(String driverId,ModelMap model){
		
		Driver driver = driverDao.get(driverId);//车手信息
		Picture example = new Picture();
		example.setBusinessId(driverId);
		example.setMoudleType(ModuleEnum.DRIVER_TWZX.name());
		List<Picture> twzxList = pictureDao.findByExample(example, 0, 4); //图文资讯
		
		example.setMoudleType(ModuleEnum.DRIVER_ZYSY.name());
		List<Picture> zysyList = pictureDao.findByExample(example); //职业生涯
		
		model.put("driver", driver);
		model.put("twzxList", twzxList);
		model.put("zysyList", zysyList);
		model.put("moudleType", ModuleEnum.DRIVER_ZYSY.name());
		return "/front/driver";
	}
	
	/**
	 * <pre>
	 * 查询车队信息
	 * </pre>
	 * @param teamId
	 * @param model
	 * @return 车队列表
	 * @author Liu Jun, 2014-5-23 下午5:36:47
	 */
	@RequestMapping("/team")
	public String team(String teamId,ModelMap model){
		Team team = teamDao.get(teamId);
		Picture twzx = new Picture();
		twzx.setBusinessId(teamId);
		twzx.setMoudleType(ModuleEnum.TEAM_TWZX.name());
		List<Picture> twzxList = pictureDao.findByExample(twzx, 0, 4); //图文资讯
		List<Driver> driverList = driverDao.getAll();  //车队车手
		List<Sponsor> sponsorList = sponsorTeamDao.getSponsorTeamList(teamId); //赞助商
		
		model.put("team", team);
		model.put("twzxList", twzxList);
		model.put("driverList", driverList);
		model.put("sponsorList", sponsorList);
		model.put("moudleType", ModuleEnum.TEAM_TWZX.name());
		return "/front/team";
	}
	
}
